/*
 *  $TEAM_NAME Space Trader
 */
package presenters;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Container;

/**
 * Abstract presenter template
 * @author bradley
 * @version 1.0
 * @param <V> - the type of view to present
 */
public class Presenter<V extends JPanel> {
	/**
	 * field
	 */
	protected JFrame frame;

	/**
	 * field
	 */
	protected V view;

    /**
     * Default constructor
     */
    public Presenter() {
        this(null);
    }

    /**
     * Creates a new presenter with the JFrame
     * @param frame - the frame
     */
    public Presenter(JFrame frame) {
        this.frame = frame;
    }

    /**
     * Getter for the frame
     * @return - gets the frame
     */
    public JFrame getFrame() {
        return frame;
    }
    
    /**
     * Sets the frame
     * @param frame - the frame to set
     */
    public void setFrame(JFrame frame) {
        this.frame = frame;
    }

    /**
     * Getter for the view
     * @return - gets the view
     */
    public V getView() {
        return view;
    }

    /**
     * Sets the view
     * @param view - the view to set
     */
    public void setView(V view) {
        this.view = view;
    }

    /**
     * Adds the view to the frame (aka presents the view)
     * @param presenter
     */
    public void present(Presenter<?> presenter) {
        final Container contentPane = frame.getContentPane();

        contentPane.removeAll();
        contentPane.repaint();

        presenter.setFrame(frame);
        contentPane.add(presenter.getView());

        frame.validate();
    }
    
    /**
     * to string
     * @return string
     */
    public String toString() {
    	return "";
    }
}
